package com.zzyl.nursing.controller.member;

import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.core.domain.R;
import com.zzyl.nursing.domain.PropertyStatusInfo;
import com.zzyl.nursing.dto.*;
import com.zzyl.nursing.service.IFamilyMemberElderService;
import com.zzyl.nursing.service.IFamilyMemberService;
import com.zzyl.nursing.vo.LoginVo;
import com.zzyl.nursing.vo.MyFamilyPageVo;
import com.zzyl.nursing.vo.MyFamilyVo;
import com.zzyl.nursing.vo.QueryDeviceDataListVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 老人家属Controller
 *
 * @author JBY
 * @date 2025-08-20
 */
@Api(tags = "老人家属管理")
@RestController
@RequestMapping("/member/user")
@Slf4j
public class FamilyMemberController extends BaseController {
    @Autowired
    private IFamilyMemberService familyMemberService;
    @Autowired
    private IFamilyMemberElderService familyMemberElderService;
    /**
     * 分页查询
     * @param
     * @return
     */
    @GetMapping("/list-by-page")
    public R<List<MyFamilyPageVo>> listByPage(PageQueryDto pageQueryDto) {
      return R.ok(familyMemberService.listByPage(pageQueryDto));

    }



    /**
     * 查询家人列表
     * @param
     * @return
     */
    @GetMapping("/my")
    public R<List<MyFamilyVo>> listQuery()
    {

        return R.ok(familyMemberService.selectMyFamily());
    }


    /**
     * 绑定家人
     * @param
     * @return
     */
    @PostMapping("/add")
    public AjaxResult add(@RequestBody AddFamilyDto addFamilyDto) {
        return toAjax(familyMemberElderService.add(addFamilyDto));
    }



    /**
     * C端登录验证
     *
     * @param userLoginRequestDto
     * @return LoginVo
     */
    @ApiOperation("C端登录验证")
    @PostMapping("/login")
    public R<LoginVo> login(@RequestBody @ApiParam("登录参数") UserLoginRequestDto userLoginRequestDto) {
        return R.ok(familyMemberService.login(userLoginRequestDto));
    }

    /* *//**
     * 查询老人家属列表
     *//*
    @ApiOperation("查询老人家属列表")
    @PreAuthorize("@ss.hasPermi('member:member:list')")
    @GetMapping("/list")
    public TableDataInfo<List<FamilyMember>> list(@ApiParam("老人家属查询条件") FamilyMember familyMember)
    {
        startPage();
        List<FamilyMember> list = familyMemberService.selectFamilyMemberList(familyMember);
        return getDataTable(list);
    }

    *//**
     * 导出老人家属列表
     *//*
    @ApiOperation("导出老人家属列表")
    @PreAuthorize("@ss.hasPermi('member:member:export')")
    @Log(title = "老人家属", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(@ApiParam(value = "老人家属查询条件") HttpServletResponse response, FamilyMember familyMember)
    {
        List<FamilyMember> list = familyMemberService.selectFamilyMemberList(familyMember);
        ExcelUtil<FamilyMember> util = new ExcelUtil<FamilyMember>(FamilyMember.class);
        util.exportExcel(response, list, "老人家属数据");
    }

    *//**
     * 获取老人家属详细信息
     *//*
    @ApiOperation("获取老人家属详细信息")
    @PreAuthorize("@ss.hasPermi('member:member:query')")
    @GetMapping(value = "/{id}")
    public R<FamilyMember> getInfo(@ApiParam("老人家属ID") @PathVariable("id") Long id)
    {
        return R.ok(familyMemberService.selectFamilyMemberById(id));
    }

    *//**
     * 新增老人家属
     *//*
    @ApiOperation("新增老人家属")
    @PreAuthorize("@ss.hasPermi('member:member:add')")
    @Log(title = "老人家属", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@ApiParam("老人家属信息") @RequestBody FamilyMember familyMember)
    {
        return toAjax(familyMemberService.insertFamilyMember(familyMember));
    }

    *//**
     * 修改老人家属
     *//*
    @ApiOperation("修改老人家属")
    @PreAuthorize("@ss.hasPermi('member:member:edit')")
    @Log(title = "老人家属", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@ApiParam("老人家属信息") @RequestBody FamilyMember familyMember)
    {
        return toAjax(familyMemberService.updateFamilyMember(familyMember));
    }

    *//**
     * 删除老人家属
     *//*
    @ApiOperation("删除老人家属")
    @PreAuthorize("@ss.hasPermi('member:member:remove')")
    @Log(title = "老人家属", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@ApiParam("老人家属ID数组") @PathVariable Long[] ids)
    {
        return toAjax(familyMemberService.deleteFamilyMemberByIds(ids));
    }*/

    /**
     * 查询健康数据
     *
     * @param
     * @return
     */
    @ApiOperation("查询健康数据")
    @PostMapping("/QueryDevicePropertyStatus")
    public R<List<PropertyStatusInfo>> QueryDevicePropertyStatus(
            @ApiParam("设备ID") @RequestBody DeviceDto deviceDto) {
        return R.ok(familyMemberService.QueryDevicePropertyStatus(deviceDto));
    }

    /**
     * 按天统计查询指标数据
     *
     * @param
     * @return
     */
    @ApiOperation("按天统计查询指标数据")
    @GetMapping("/queryDeviceDataListByDay")
    public R<List<QueryDeviceDataListVo>> queryDeviceDataListBy(@RequestBody QueryDeviceDataListDto queryDeviceDataListDto) {
        return R.ok(familyMemberService.queryDeviceDataListByDay(queryDeviceDataListDto));
    }

    /**
     * 按周统计查询指标数据
     *
     * @param
     * @return
     */
    @ApiOperation("按周统计查询指标数据")
    @GetMapping("/queryDeviceDataListByWeek")
    public R<List<QueryDeviceDataListVo>> queryDeviceDataListByWeek(@RequestBody QueryDeviceDataListDto queryDeviceDataListDto) {
        return R.ok(familyMemberService.queryDeviceDataListByWeek(queryDeviceDataListDto));
    }
}
